{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "bc7ac176-085b-49e6-8075-a229fe08908c",
   "metadata": {},
   "source": [
    "# Common pitfalls in NGSolve\n",
    "\n",
    "Here is list of common pitfalls many NGSolve users have experienced. We try to catch most of them, but some are difficult or even impossible to detect. We also try not to be over-restrictive in using NGSolve classes."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8bdbd1d3-6fb7-41aa-9e2b-9dacb885424c",
   "metadata": {},
   "source": [
    "## General Python usage\n",
    "\n",
    "- The *assignment operator =* in Python does not assign to an existing variable, but defines a new object\n",
    "  \n",
    "    ```\n",
    "    x = CreateVVector(5)\n",
    "    y = CreateVVector(5)\n",
    "    x[:] = 3\n",
    "    y = 2*x\n",
    "    ```\n",
    "  The new object is `DynamicVectorExpression`, which can be evaluated useing `y.Evaluate()` \n",
    "    \n",
    "- We define `x`, `y`, `z` for simply usage of Cartesian coordinates. It is easy to overwrite them, like:\n",
    "\n",
    "     ```\n",
    "     for x in np.linspace(1,5,10):\n",
    "        l.append (x)\n",
    "     ...\n",
    "     Integrate (x*y, mesh)\n",
    "     ``` "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c7b6de20-ca77-4b65-80d5-22d8736a746a",
   "metadata": {},
   "source": [
    "## Geometric modeling\n",
    "\n",
    "- Don't forget to specify the dimension if you want to generate a 2D mesh:\n",
    "```\n",
    "rect = Rectangle(3,5).Face()\n",
    "mesh = OCCGeometry(rect, dim=2).GenerateMesh(maxh=1)\n",
    "```\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "06047eb6-9f17-445c-bb54-7a33014ce39a",
   "metadata": {},
   "source": [
    "## NGSolve\n",
    "\n",
    "* Setting boundary conditions:\n",
    "\n",
    "  ```\n",
    "  fes = H1(mesh, order=2, dirichlet=\"bot\")\n",
    "  gfu = GridFunction(fes)\n",
    "  gfu.Set(x,BND) \n",
    "  ```\n",
    "\n",
    "  Sets boundary values only on Dirichlet boundary. Use `gfu.Set(x, mesh.Boundaries(\".*\"))` on the whole boundary."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b9339924-dcbe-4be4-904e-3e2e18ba2b8b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
